using Daemon.Infrustructure.EF;
using Daemon.Repository.EF.Enums;
using Daemon.Repository.Contract;
using Daemon.Model;
using System;
using System.Linq.Expressions;
using System.Linq;
using System.Collections.Generic;

namespace Daemon.Repository.EF
{
    public class StudentImportTemplateRepository : Repository<StudentImportTemplate>, IStudentImportTemplateRepository
    {
        protected override Expression<Func<StudentImportTemplate, int>> PrimaryKeyExpression => r => r.Id;

        public StudentImportTemplateRepository(ApiDBContent context) : base(context)
        {

        }

        protected override void UpdateEntitiesBeforeCreate(IEnumerable<StudentImportTemplate> entities, ApiDBContent context)
        {
           foreach (var entity in entities)
           {
                entity.UserId = AuthInfo.UserId;
            }
        }

        protected override IQueryable<StudentImportTemplate> FilterByAuthInfo(IQueryable<StudentImportTemplate> queryable, ApiDBContent context)
        {
            if (AuthInfo.IsAdmin)
            {
                return queryable;
            }

            queryable = queryable.Where(r => r.UserId == AuthInfo.UserId);
            return queryable;
        }
    }
}